<template>
  <div>
    <div class="my-goods-item" v-for="item in list" :key="item.id">
      <div class="left">
        <div class="custom-control custom-checkbox">
          <input
            type="checkbox"
            class="custom-control-input"
            id="input"
            :checked="item.goods_state"
            @change="$emit('edit', item.id)"
          />
          <label class="custom-control-label" for="input">
            <img :src="item.goods_img" alt="" />
          </label>
        </div>
      </div>
      <div class="right">
        <div class="top">{{ item.goods_name }}</div>
        <div class="bottom">
          <span class="price">¥ {{ item.goods_price }}</span>
          <template>
            <div class="my-counter">
              <button type="button" class="btn btn-light" @click="$emit('count', item.id)">-</button>
              <input
                type="number"
                class="form-control inp"
                :value="item.goods_count"
                @keyup.enter="enterFn(item.id,$event)"
              />
              <button
                type="button"
                class="btn btn-light"
                @click="$emit('addCount', item.id)"
              >
                +
              </button>
            </div>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import MyCount from "@/components/MyCount";
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
    id: Number,
  },
  methods:{
    enterFn(id,e) {
      // console.log(e.target.value);
      this.$emit('enter',id,e.target.value)
    }
  }
  
  
};
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
.my-goods-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  .left {
    img {
      width: 120px;
      height: 120px;
      margin-right: 8px;
      border-radius: 10px;
    }
    .custom-control-label::before,
    .custom-control-label::after {
      top: 50px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top {
      font-size: 14px;
      font-weight: 700;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      padding: 5px 0;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>